package net.adst.ui.mainframe;

import net.adst.resources.Constants;
import net.adst.ui.mainframe.tabs.AdstTabPanel;
import net.adst.ui.mainframe.toppanel.TopPanel;
import net.adst.ui.other.InfoBar;
import net.adst.util.GBC;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

/**
 * Created with IntelliJ IDEA.
 * User: alekseipot
 * Date: 01.11.12
 * Time: 4:45
 * To change this template use File | Settings | File Templates.
 */
public class MainFrame extends JFrame {

    private TopPanel topPanel = new TopPanel();

    public MainFrame() {
    }

    public void init() {
        setSizeAndCentered();
        setTitle(Constants.FRAME_TITLE);
        URL url = ClassLoader.getSystemResource("images/icon.PNG");
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.createImage(url);
        setIconImage(image);
        Container cp = getContentPane();
        cp.setLayout(new GridBagLayout());
        cp.add(topPanel, new GBC(0, 1).setFill(GBC.HORIZONTAL));
        cp.add(new AdstTabPanel(), new GBC(0, 2).setFill(GBC.BOTH).setWeight(1, 1));
        cp.add(new InfoBar(), new GBC(0, 3).setAnchor(GBC.EAST));
    }

    public void hideOrShowTopPanel(boolean hide) {
//        topPanel.hidePanel(hide);
    }

    /**
     * Sets frame size (2/3 screen dimension) and location (center)
     */
    private void setSizeAndCentered() {
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension screenSize = tk.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        int frameWidth = screenWidth * 2 / 3;
        int frameHeight = screenHeight * 2 / 3;
//        if (frameWidth < OrsConstants.MIN_WIDTH) {
//            frameWidth = OrsConstants.MIN_WIDTH;
//        }
//        if (frameHeight < OrsConstants.MIN_HEIGHT) {
//            frameHeight = OrsConstants.MIN_HEIGHT;
//        }
        setLocation((screenWidth - frameWidth) / 3, (screenHeight - frameHeight) / 3);
    }


}
